package com.atom.module.coroutine.test


import com.atom.module.coroutine.context.CoroutineName
import com.atom.module.coroutine.core.*
import com.atom.module.coroutine.core.launch
import com.atom.module.coroutine.exception.CoroutineExceptionHandler
import com.atom.module.coroutine.scope.GlobalScope
import com.atom.module.coroutine.utils.log


suspend fun main() {

    val exceptionHandler = CoroutineExceptionHandler { coroutineContext, throwable ->
        log("[ExceptionHandler]", coroutineContext[CoroutineName], throwable.message)
    }

    val context = exceptionHandler + CoroutineName("MyCoroutine")

    GlobalScope.launch(context) {
        log(1)
        throw ArithmeticException("Div by 0")
        log(2)
    }.join()
}